/*
 * @Author: 余其方 448919239@qq.com
 * @Date: 2022-08-02 20:22:38
 * @LastEditors: 余其方 448919239@qq.com
 * @LastEditTime: 2022-09-01 19:06:38
 * @FilePath: /redux-demo/src/index.js
 * @Description:
 *
 * Copyright (c) 2022 by 余其方 448919239@qq.com, All Rights Reserved.
 */
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals"; // 记录web的核心指标

import { persistor, store } from "./store";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/lib/integration/react";
import { BrowserRouter } from "react-router-dom";

const root = ReactDOM.createRoot(document.getElementById("root"));
// root.render(<App />);

// 使用store.subscribe方法设置监听函数，一旦 State 发生变化，就自动执行这个函数。
store.subscribe(() => {
  root.render(
    <Provider store={store}>
      <PersistGate loading={null} persistor={persistor}>
        <BrowserRouter>
          <App />
        </BrowserRouter>
      </PersistGate>
    </Provider>
  );
});

// If you want to start measuring performance in your app, pass a function
// 如果您想开始在应用程序中测量性能，请传递一个函数
// to log results (for example: reportWebVitals(console.log))
// 以记录结果（例如：reportWebVitals(console.log)）
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals(); // 记录web的核心指标
